/*
 * frmTraining.java
 *
 * Created on April 28, 2010, 5:33 PM
 */
package GUI;

import ConnectDB.ConnectDB;
import Entity.Training;
import Validate_Connect.CheckForm;
import Validate_Connect.DataInteraction;
import Validate_Connect.GUIInteraction;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author  Shinichi
 */
public class frmTraining extends javax.swing.JInternalFrame {

    /** Creates new form frmTraining */
    public frmTraining() {
        LookAndFeelWindow.LookAndFeelWindow.LookAndFeelWindow();
        initComponents();
        refresh();
        _txtTrainID.setEditable(false);
        _txtTrainName.setEditable(false);
        _txtDescription.setEditable(false);
        _btndelete.setEnabled(false);
        _btnupdate.setEnabled(false);
        _btnreset.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel4 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        _txtTrainID = new javax.swing.JTextField();
        _txtTrainName = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        _txtDescription = new javax.swing.JTextPane();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        _tblTrainingList = new javax.swing.JTable(){
            public boolean isCellEditable(int rowIndex, int colIndex) {
                return false;   //Disallow the editing of any cell
            }
        };
        _tblTrainingList.getTableHeader().setReorderingAllowed(false);
        _btnclose = new javax.swing.JButton();
        _btnprint = new javax.swing.JButton();
        _btnreset = new javax.swing.JButton();
        _btnupdate = new javax.swing.JButton();
        _btndelete = new javax.swing.JButton();
        _btnaddNew = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();

        setClosable(true);
        setIconifiable(true);
        setTitle("AITSM - Trainings");

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Information"));

        jLabel1.setText("Train ID:");

        jLabel2.setText("Train Name:");

        jLabel3.setText("Description:");

        jScrollPane1.setViewportView(_txtDescription);

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(27, 27, 27)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jLabel2)
                        .add(33, 33, 33)
                        .add(_txtTrainName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 167, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel1)
                            .add(jLabel3))
                        .add(34, 34, 34)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 229, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(_txtTrainID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 69, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(30, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(_txtTrainID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(_txtTrainName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(7, 7, 7)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(14, 14, 14)
                        .add(jLabel3))
                    .add(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 110, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Training List"));

        _tblTrainingList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        _tblTrainingList.setSelectionBackground(new java.awt.Color(153, 153, 255));
        _tblTrainingList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                _tblTrainingListMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(_tblTrainingList);

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 394, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 237, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        _btnclose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Logout16x16.png"))); // NOI18N
        _btnclose.setText("Close");
        _btnclose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btncloseActionPerformed(evt);
            }
        });

        _btnprint.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/printer2.png"))); // NOI18N
        _btnprint.setText("Print");
        _btnprint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnprintActionPerformed(evt);
            }
        });

        _btnreset.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/reset2.png"))); // NOI18N
        _btnreset.setText("Reset");
        _btnreset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnresetActionPerformed(evt);
            }
        });

        _btnupdate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/update2.png"))); // NOI18N
        _btnupdate.setText("Update");
        _btnupdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnupdateActionPerformed(evt);
            }
        });

        _btndelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Delete2.png"))); // NOI18N
        _btndelete.setText("Delete");
        _btndelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btndeleteActionPerformed(evt);
            }
        });

        _btnaddNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/list_add2.png"))); // NOI18N
        _btnaddNew.setText("Add New");
        _btnaddNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnaddNewActionPerformed(evt);
            }
        });

        jPanel2.setBackground(new java.awt.Color(0, 102, 153));

        jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 36));
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Trainings");

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(338, 338, 338)
                .add(jLabel4)
                .addContainerGap(374, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(jLabel4)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(_btndelete, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(_btnaddNew))
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel4Layout.createSequentialGroup()
                                .add(30, 30, 30)
                                .add(_btnreset, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 102, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
                                .add(30, 30, 30)
                                .add(_btnupdate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 102, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .add(31, 31, 31)
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(_btnprint, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 104, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(_btnclose, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 104, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(22, 22, 22))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(_btnaddNew)
                            .add(_btnreset)
                            .add(_btnprint))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(_btnupdate)
                            .add(_btndelete)
                            .add(_btnclose)))
                    .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void _btndeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btndeleteActionPerformed
    String _id = _txtTrainID.getText();
    int i = JOptionPane.showConfirmDialog(null, "Do you want to delete " + _txtTrainName.getText(), "Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (i == 0) {
        Interact.Trainings.deleteTraining(_id);
    }        
    resetForm();
    refresh();
    _btnreset.setEnabled(false);
    _btndelete.setEnabled(false);
    _btnupdate.setEnabled(false);
}//GEN-LAST:event__btndeleteActionPerformed

private void _btnaddNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnaddNewActionPerformed
    if (_btnaddNew.getText().equals("Add New")) {
        resetForm();
        _btnaddNew.setText("Save");
        _txtTrainID.setEditable(true);
        _txtTrainName.setEditable(true);
        _txtDescription.setEditable(true);
        _btnclose.setEnabled(false);
        _btndelete.setEnabled(false);
        _btnprint.setEnabled(false);
        _btnreset.setEnabled(false);
        _btnupdate.setEnabled(false);
    } else {
        if (!validateForm()) {
            return;
        }
        Entity.Training train = new Training(_txtTrainID.getText(), _txtTrainName.getText(), _txtDescription.getText());
        Interact.Trainings.insertTraining(train);
        JOptionPane.showMessageDialog(null, "Insert succesfull", "Message", JOptionPane.INFORMATION_MESSAGE);
        resetForm();
        refresh();
        _txtTrainID.setEditable(false);
        _txtTrainName.setEditable(false);
        _txtDescription.setEditable(false);
        _btnaddNew.setText("Add New");
        _btnreset.setEnabled(false);
        _btndelete.setEnabled(false);
        _btnupdate.setEnabled(false);
        _btnprint.setEnabled(true);
        _btnclose.setEnabled(true);
    }


}//GEN-LAST:event__btnaddNewActionPerformed

private void _btnresetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnresetActionPerformed
    resetForm();
    _btnreset.setEnabled(false);
    _btndelete.setEnabled(false);
    _btnupdate.setEnabled(false);
}//GEN-LAST:event__btnresetActionPerformed

private void _btnupdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnupdateActionPerformed
    if (_btnupdate.getText().equals("Update")) {
        _txtTrainID.setEditable(true);
        _txtTrainName.setEditable(true);
        _txtDescription.setEditable(true);
        _btnupdate.setText("Save");
        _btnaddNew.setEnabled(false);
        _btndelete.setEnabled(false);
        _btnprint.setEnabled(false);
        _btnreset.setEnabled(false);
    } else {
        Entity.Training train = new Training(_txtTrainID.getText(), _txtTrainName.getText(), _txtDescription.getText());
        Interact.Trainings.updateTraining(train);
        JOptionPane.showMessageDialog(null, "Update succesfull", "Message", JOptionPane.INFORMATION_MESSAGE);
        resetForm();
        refresh();
        _txtTrainID.setEditable(false);
        _txtTrainName.setEditable(false);
        _txtDescription.setEditable(false);
        _btnupdate.setText("Update");
        _btnaddNew.setEnabled(true);
        _btndelete.setEnabled(false);
        _btnprint.setEnabled(true);
        _btnreset.setEnabled(false);
        _btnupdate.setEnabled(false);
    }


}//GEN-LAST:event__btnupdateActionPerformed

private void _btnprintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnprintActionPerformed
    ConnectDB.runReport("src\\Report\\reportTrainingList.jasper");
}//GEN-LAST:event__btnprintActionPerformed

private void _btncloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btncloseActionPerformed

    this.dispose();

}//GEN-LAST:event__btncloseActionPerformed

private void _tblTrainingListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event__tblTrainingListMouseClicked
    int i = _tblTrainingList.getSelectedRow();
    _txtTrainID.setText(String.valueOf(_tblTrainingList.getValueAt(i, 0)));
    _txtTrainName.setText(String.valueOf(_tblTrainingList.getValueAt(i, 1)));
    _txtDescription.setText(String.valueOf(_tblTrainingList.getValueAt(i, 2)));
    _btnreset.setEnabled(true);
    _btndelete.setEnabled(true);
    _btnupdate.setEnabled(true);
    _btnprint.setEnabled(true);
    _btnclose.setEnabled(true);
    _txtTrainID.setEditable(false);
    _txtTrainName.setEditable(false);
    _txtDescription.setEditable(false);
    if (_btnaddNew.getText().equals("Save")) {
        _btnaddNew.setText("Add New");
    }
    if(_btnupdate.getText().equals("Save")){
        _btnupdate.setText("Update");
    }
    _btnaddNew.setEnabled(true);
}//GEN-LAST:event__tblTrainingListMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton _btnaddNew;
    private javax.swing.JButton _btnclose;
    private javax.swing.JButton _btndelete;
    private javax.swing.JButton _btnprint;
    private javax.swing.JButton _btnreset;
    private javax.swing.JButton _btnupdate;
    private javax.swing.JTable _tblTrainingList;
    private javax.swing.JTextPane _txtDescription;
    private javax.swing.JTextField _txtTrainID;
    private javax.swing.JTextField _txtTrainName;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables

    public void resetForm() {
        _txtTrainID.setText("");
        _txtTrainName.setText("");
        _txtDescription.setText("");
    }

    public void refresh() {
        try {
            GUIInteraction.readToTable("select * from tblTrainings", _tblTrainingList);
        } catch (SQLException ex) {
            Logger.getLogger(frmTraining.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public boolean validateForm() {
        if (!CheckForm.isEmpty(_txtTrainID.getText())) {
            JOptionPane.showMessageDialog(null, "Please enter Training ID", "Error", JOptionPane.ERROR_MESSAGE);
            _txtTrainID.requestFocus();
            return false;
        }
        if (!CheckForm.isWhiteSpace(_txtTrainID.getText())) {
            JOptionPane.showMessageDialog(null, "Training ID is invalid", "Error", JOptionPane.ERROR_MESSAGE);
            _txtTrainID.requestFocus();
            return false;
        }
        if (!GUIInteraction.checkDuplicateID(_txtTrainID.getText(), "select * from tblTrainings", "TrainID")) {
            JOptionPane.showMessageDialog(null, "Training ID is duplication", "Error", JOptionPane.ERROR_MESSAGE);
            _txtTrainID.requestFocus();
            return false;
        }
        if (!CheckForm.isEmpty(_txtTrainName.getText())) {
            JOptionPane.showMessageDialog(null, "Please enter Training Name", "Error", JOptionPane.ERROR_MESSAGE);
            _txtTrainName.requestFocus();
            return false;
        }
        if (!GUIInteraction.checkDuplicateID(_txtTrainName.getText(), "select * from tblTrainings", "TrainName")) {
            JOptionPane.showMessageDialog(null, "Training name is duplication", "Error", JOptionPane.ERROR_MESSAGE);
            _txtTrainName.requestFocus();
            return false;
        }
        if (!CheckForm.isEmpty(_txtDescription.getText())) {
            JOptionPane.showMessageDialog(null, "Please enter Description", "Error", JOptionPane.ERROR_MESSAGE);
            _txtDescription.requestFocus();
            return false;
        }
        return true;
    }
}
